//
//  OPSettingController.m
//  OnePiece
//
//  Created by wsy on 15/11/2.
//  Copyright © 2015年 wsy. All rights reserved.
//

#import "OPSettingController.h"
#import "OPTreatyController.h"
#import "OPAboutUsController.h"
#import <SDImageCache.h>
@interface OPSettingController ()
@property (nonatomic, assign) CGFloat size;
@end

@implementation OPSettingController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.topView.backgroundColor = [UIColor colorWithRed:0.945 green:0.458 blue:0.299 alpha:1.000];
    self.titleLable.text = @"设置";
    self.titleLable.textColor = [UIColor whiteColor];
    [self.leftButton addTarget:self action:@selector(back) forControlEvents:(UIControlEventTouchUpInside)];
    [self.leftButton setImage:[UIImage imageNamed:@"iconfont-weibiaoti1"] forState:(UIControlStateNormal)];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor colorWithRed:0.945 green:0.458 blue:0.299 alpha:1.000];
    self.size = [[SDImageCache sharedImageCache]getSize]/1024/1024.0;
    
    
    
    [self configureview];

}
- (void)configureview
{
    UIButton *clear = [UIButton buttonWithType:(UIButtonTypeCustom)];
    clear.frame = CGRectMake(30, 120, SCREEN_WIDTH-60, 30);
    [clear setTitle:[NSString stringWithFormat:@"清除缓存  %.2fM", _size] forState:(UIControlStateNormal)];
    clear.layer.borderColor = [[UIColor whiteColor] CGColor];
    clear.layer.borderWidth = 1.5;
    clear.layer.cornerRadius = 5;
    [clear addTarget:self action:@selector(clear:) forControlEvents:(UIControlEventTouchUpInside)];
    [self.view addSubview:clear];
    UIButton *us = [UIButton buttonWithType:(UIButtonTypeCustom)];
    us.frame = CGRectMake(30, 180, SCREEN_WIDTH-60, 30);
    [us setTitle:@"关于我们" forState:(UIControlStateNormal)];
    us.layer.borderColor = [[UIColor whiteColor] CGColor];
    us.layer.borderWidth = 1.5;
    us.layer.cornerRadius = 5;
    [us addTarget:self action:@selector(toUs) forControlEvents:(UIControlEventTouchUpInside)];
    [self.view addSubview:us];
    UIButton *treaty = [UIButton buttonWithType:(UIButtonTypeCustom)];
    treaty.frame = CGRectMake(30, 240, SCREEN_WIDTH-60, 30);
    [treaty setTitle:@"用户协议" forState:(UIControlStateNormal)];
    treaty.layer.borderColor = [[UIColor whiteColor] CGColor];
    treaty.layer.borderWidth = 1.5;
    treaty.layer.cornerRadius = 5;
    [treaty addTarget:self action:@selector(toTreaty) forControlEvents:(UIControlEventTouchUpInside)];
    [self.view addSubview:treaty];
    
}

- (void)toTreaty
{
    OPTreatyController *treatyVC = [[OPTreatyController alloc]init];
    [self presentViewController:treatyVC animated:YES completion:nil];
    
}
- (void)toUs
{
    OPAboutUsController *usVC = [[OPAboutUsController alloc]init];
    [self presentViewController:usVC animated:YES completion:nil];
}
- (void)clear:(UIButton *)sender
{
    [[SDImageCache sharedImageCache] clearDisk];
    [[SDImageCache sharedImageCache]clearMemory];
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:nil message:@"清除缓存成功" preferredStyle:(UIAlertControllerStyleAlert)];
    UIAlertAction *ensure = [UIAlertAction actionWithTitle:@"确定" style:(UIAlertActionStyleDefault) handler:nil];
    [alert addAction:ensure];
    [self presentViewController:alert animated:YES completion:nil];
    self.size = [[SDImageCache sharedImageCache]getSize]/1024/1024;
    [sender setTitle:[NSString stringWithFormat:@"清除缓存  %.2fM", _size] forState:(UIControlStateNormal)];
}

- (void)back
{
    [self.navigationController popViewControllerAnimated:YES];
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
